<template>
	<view class="">
		<view class="mt-10">
			<u--form errorType="toast" :model="form" ref="myForm" :rules="rules" labelWidth="80">
				<u-form-item label="财务类型" prop="direction" borderBottom>
					<u-radio-group slot="right" v-model="form.direction" activeColor="#e54d42">
						<u-radio :name="-1" label="实际支付"></u-radio>
						<u-radio :name="1" label="实际收入"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="交易方式" prop="paymentName" borderBottom @click="showPicker=true">
					<u-input v-model="form.paymentName" disabled disabledColor="#ffffff" border="none" inputAlign="right"/>
					<u-icon slot="right" name="arrow-right" />
				</u-form-item>
				<u-form-item label="记录金额" prop="amount" borderBottom>
					<u-input v-model="form.amount" border="none" type="number" placeholder="请输入金额" inputAlign="right"/>
				</u-form-item>
				<u-form-item label="备注信息" prop="explain">
					<u-input v-model="form.explain" placeholder="请输入备注信息" border="none" inputAlign="right" />
				</u-form-item>
			</u--form>
		</view>
		<view class="pl-30 pr-30 mt-40">
			<u-button color="#e54d42" text="保存" @click="submit" size="large"/>
		</view>
		<u-picker 
			:show="showPicker" 
			:columns="pickerColumns" 
			@cancel="showPicker=false" 
			@close="showPicker=false"
			@confirm="confirmVal"
			:closeOnClickOverlay="true"
		/>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPicker: false,
				pickerColumns:[[
					{text:'微信支付', value:1},
					{text:'支付宝支付', value:2},
					{text:'线下支付', value:3},
					{text:'余额支付', value:4},
					{text:'股本消费', value:5},
				]],
				form: {
					direction: -1,
					paymentCode: 1,
					paymentName:'微信支付',
					amount: '',
					explain: ''
				},
				rules: {
					amount: [{
						required: true,
						message: '请输入金额',
						trigger: ['blur', 'change']
					}],
					explain: [
						{
							required: true,
							message: '请输入备注信息',
							trigger: ['blur', 'change']
						}
					],
				}
			}
		},
		onLoad() {	
			
		},
		onReady() {
			this.$refs.myForm.setRules(this.rules)
		},
		methods: {
			confirmVal(e){
				this.form.paymentCode = e.value[0].value
				this.form.paymentName = e.value[0].text
				this.showPicker = false
			},
			submit() {
				const that = this
				that.$refs.myForm.validate().then(res => {
					that.$reqJsonPost('FinanceAccountDoCreate', that.form).then(res => {
						that.$refs.uToast.show({
							message: res.msg,
							complete() {
								uni.$emit('upFinancialList', true)
								uni.redirectTo({url:'/pages/finance/statement'});
							}
						})
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
